package com.zyx.crawlerdemo.htmlxmlparse.xml;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 * @author Yaxi.Zhang
 * @since 2021/8/12 10:04
 * desc: jsoup解析xml
 */
public class JsoupXml {
    public static void main(String[] args) throws IOException {
        //获取URL对应的HTML内容
        String url = "http://db.auto.****.com/cxdata/xml/sales/model/model1001sales.xml";
        Document doc = Jsoup.connect(url).timeout(5000).get();
        //Jsoup选择器解析
        Elements salesEle = doc.select("sales");
        for (Element elem : salesEle) {
            int salesnum = Integer.parseInt(elem.attr("salesnum"));
            String date = elem.attr("date");
            System.out.println("月份:" + date + "\t销量:" + salesnum);
        }
    }

}
